<#assign  title="退货申请" />
<#include 'common/header.html'>
<#--创建“订单货物列表”标签-->
<#assign orderChildItemListTag = newTag("orderChildItemListTag")>
<#--调用“订单货物列表”标签，并传递参数-->
<#assign map = orderChildItemListTag("{'orderid':${order_id}}")>
<#--创建"支付列表"标签-->
<#assign shopPaymentListTag= newTag("shopPaymentListTag") >    
<#--调用"支付列表"标签-->          
<#assign paymentList = shopPaymentListTag()>
<#assign orderChildItemListTag = newTag("orderItemListTag")>
<#--调用“订单货物列表”标签，并传递参数-->
<#assign orderItemList = orderChildItemListTag("{'orderid':${order_id}}")>

<link rel="stylesheet" type="text/css" href="themes/wap/css/member.css" />
<div class="header-tools">
	<div class="go-back">
		<a href="javascript:" onclick="window.history.go(-1);"></a>
	</div>
	<div class="common-title">
		退货申请
	</div>
	<div class="go-search">
	</div>
</div>
	<form id="returnForm">
		<div class="return_detail">
		<input type="hidden" name="orderId" value="${order_id}" />
		<input type = "hidden" id = "packDetailJson" name = "packDetailJson" />
		<h2>请选择要退货的商品</h2>
		<table class="return-goods-list">
			<#list orderItemList as item>	
			<tr>
				<td>
					<#if item.state==0 >
					<div class="c-list">
						<label class="store-goods-ch">
							<input type="checkbox" style="display:none;" class="need_sync input-box" name="goodsId" value="${item.goods_id}" goods_id="${item.goods_id}" payNum="${item.num}" autocomplete="off"/>
						</label>
						<span style="display:none">
							<input type="checkbox" class="need_sync" goods_id="${item.goods_id}" name="item_id" value="${item.item_id}" autocomplete="off"/> 
							<input type="checkbox" class="need_sync" goods_id="${item.goods_id}"  name="productId" value="${item.product_id}"  autocomplete="off"/>
							<input type="checkbox" class="need_sync"  goods_id="${item.goods_id}" name="price" value="${item.price}"  autocomplete="off"/>
							<input type="checkbox" class="need_sync" goods_id="${item.goods_id}" name="payNum" value="${item.num}" autocomplete="off"/> 
						</span>
					</#if>
						<div class="c-left">
							<a href="goods-${item.goods_id}.html">
								<img  src="${item.image!''}"  style="cursor: pointer;" />
							</a>
							<h3>
								<a target="_blank" href="goods-${item.goods_id}.html">${item.name}<#if item.other?? ><span>(${item.other})</span></#if></a>
							</h3>
						</div>
						<div class="return-price">
							<div class="return-goods-price">
								<p>${item.price?string.currency} <span>x</span> ${item.num}</p>
								<span class="return-goods-box">
									<input name="goodsNum" class="input_text return-num" type="text" value="${item.num}" disabled="disabled" maxnum="${item.num}" goods_id="${item.goods_id}"    autocomplete="off" />
								</span>
							</div>
						</div>
					</div>
				</td> 
			</tr>
		</#list>
		</table>	
	</div>
	<div class="return-apply">
		<h4>请选择退款方式</h4>
		<select name="refund_way"> 
			<option value="0">-- 请选择退款方式 --</option>
			<#list paymentList as payment  >
				<#if payment.type!="cod">
					<option value="${payment.name}"> ${payment.name} </option>
				</#if>
			</#list>
		</select>
		<h4>请选择退款账户</h4>
			<input type="text" name="return_account" class="return-way-name"/>
		<h4>问题描述</h4>
		<div class="return-word">
			<textarea name="remark" maxlength="100"></textarea>
		</div>
		<div class="return-tools btn">
			<input type="button" name="btnSubmit" value="申请退货" id="btnSubmit" class="save-info" />
		</div>
	</div>
</form>


<!--会员中心首页右侧结束-->
<script type="text/javascript">

$(".store-goods-ch").click(function(){
	if($(this).find("input").is(':checked')){
		$(this).addClass("selected");
	}else{
		$(this).removeClass("selected");
	}
})

$(function(){
	
	$("input[name='goodsId']").click(function(){
		var checked = this.checked;
		var goodsid  = $(this).val();
		if(checked){
			$(".need_sync[goods_id="+goodsid+"]").attr("checked","checked");
			$("[name=goodsNum][goods_id="+goodsid+"]").removeAttr("disabled");
		}else{
			$(".need_sync[goods_id="+goodsid+"]").removeAttr("checked");
			$("[name=goodsNum][goods_id="+goodsid+"]").attr("disabled","disabled");
		}
	});
	
	$("#btnSubmit").click(function(){
		
		if($("input[name='goodsId']").filter(":checked").length==0){
			alert("请选择要退货的商品");
			return false;
		}
		
		var error =0;
		
		$(".return-goods-box[name=goodsNum]").each(function(i,v){
			var $this = $(v);
			var maxnum= $this.attr("maxnum");
			var num = $this.val();
			
			if(num==""){
				alert("请输入退货数量");
				error=1;
				return ;
			}
			
			
			if(num=="0"){
				alert("退货数量不能为0");
				error=1;
				return ;
			}
			
			if (!$.isNumber(num)){
				alert("退货数量请输入数字");
				error=1;
				return ;
			}
			
			if(num>maxnum){
				alert("退货数量不能大于购物数量");
				error=1;
				return ;
			}
			
		});
		
		
		if(1==error){
			return false;
		}
		 
		if($("select[name='refund_way']").val()=="0"){
			alert("请选择支付方式");
			return false;
			
		}
		if($("input[name='return_account']").val()==""){
			alert("请填写退款账号");
			$("#btnSubmit").removeAttr("disabled");
			return false;
		}
		 
		
		$("#btnSubmit").attr("disabled",true); 
		var options = {
				url : "${ctx}/api/shop/sell-back/return-goods.do",
				type : "POST",
				dataType : 'json',
				success : function(result) {
					if(result.result==1){
						alert(result.message);
						location.href="return_list.html"
					}else{
						alert(result.message);
					}
				},
				error : function(e) {
					alert("出现错误 ，请重试");
				}
			};
			$('#returnForm').ajaxSubmit(options);
	});
	 
})
</script>
<#include 'common/float_footer.html'/>
<#include 'common/footer.html'/>	